package com.pulse.common.utils.sor.make;

import com.pulse.common.utils.sor.domain.SorInfo;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class SupParamsMake {

    public static final String SUPPLIER_PARAMS_BLOCK_ID = "SupParams\0";

    public static ByteBuffer make(SorInfo info) {
        ByteBuffer buffer = ByteBuffer.allocate(128);
        buffer.order(ByteOrder.LITTLE_ENDIAN);

        // 写入块ID
        buffer.put(SUPPLIER_PARAMS_BLOCK_ID.getBytes());

        // 写入供应商名称
        String supplier = info.getSupParams().getSupplier() == null ? "\0" : info.getSupParams().getSupplier() + "\0";
        buffer.put(supplier.getBytes());
        // 写入设备型号
        String otdr = info.getSupParams().getOtdr() == null ? "\0" : info.getSupParams().getOtdr() + "\0";
        buffer.put(otdr.getBytes());
        // 写入设备序列号
        String otdrSn = info.getSupParams().getOtdrSN() == null ? "\0" : info.getSupParams().getOtdrSN() + "\0";
        buffer.put(otdrSn.getBytes());
        // 写入光模块型号
        String modules = info.getSupParams().getModule() == null ? "\0" : info.getSupParams().getModule() + "\0";
        buffer.put(modules.getBytes());
        // 写入光模块sn
        String modulesSn = info.getSupParams().getModuleSN() == null ? "\0" : info.getSupParams().getModuleSN() + "\0";
        buffer.put(modulesSn.getBytes());
        // 软件版本
        String software = info.getSupParams().getSoftware() == null ? "\0" : info.getSupParams().getSoftware() + "\0";
        buffer.put(software.getBytes());
        // 其他
        String other = info.getSupParams().getOther() == null ? "\0" : info.getSupParams().getOther() + "\0";
        buffer.put(other.getBytes());

        return buffer;
    }
}
